package com.ezmobo.redis;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ezmobo.redis.cache.RedisCache;

@Service
public class TestRedis {
	@Autowired
	private RedisCache dao;

	@SuppressWarnings("unchecked")
	@PostConstruct
	public void init() {
		User user = new User();
		user.setId("1");
		user.setName("houge");
		user.setPassword("123456");
		dao.put(user.getId(), user);

		User user1 = (User) dao.get("1", user.getClass(), false);
		

		System.out.println(user1.getName());

		dao.remove("1");

		User user2 = (User) dao.get("1", user.getClass(), false);

		if (user2 == null) {
			System.out.println("user not exist!");
		}

		// dao.remove("list");

		List<User> list = new ArrayList<User>();

		User user3 = new User();
		user3.setId("999");
		user3.setName("houge2");
		user3.setPassword("123456");

		list.add(user1);
		list.add(user3);

		dao.put("list", list);

		List<User> list1 = (List<User>) dao.get("list", user.getClass(), true);

		System.out.println(list1.toString());

		dao.put("list", "testssssssssss");

		System.out.println(dao.get("list"));

		dao.put("map", "123", "123");
		dao.put("map", "1234", "1234");
		dao.put("map", "12345", "12356");

		System.out.println(dao.get("map", "1234"));

		dao.remove("map", "1234");

		System.out.println(dao.get("map", "1234"));
	}
}
